#include <iostream>
#include <vector>
using namespace std;
using ll=long long;
int f[26], g[26];
int main() {
    int n;
    cin >> n;
    string str;
    cin >> str;
    vector<int> dp(n);
    ll ret = 0;
    for (int i = 0; i < n; i++) {
        dp[i] = f[str[i] - 'a'];
        f[str[i] - 'a'] += i - g[str[i] - 'a'];
        g[str[i] - 'a']++;
        ret += dp[i];
    }

    cout << ret;
    return 0;
}
